/**
 * <p>Title: ServiceZMCMF1.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张小飞
 * @version 1.0
 * <pre>Histroy:
 *          2011-7-5 下午04:52:09  张小飞  Create
 *</pre>
 */
package com.baosight.sczx.zm.cm.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.Utils;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.common.zm.cInterface.User;
import com.baosight.sczx.common.zm.cInterface.cm.Depot;
import com.baosight.sczx.common.zm.cInterface.cm.MaterialBase;
import com.baosight.sczx.common.zm.cInterface.cs.InitialData;
import com.baosight.sczx.common.zm.cInterface.cs.SystemSettingCM;
import com.baosight.sczx.zm.cm.domain.ZMCMMaterialBasicInfo;
import com.baosight.sczx.zm.cm.domain.ZMCMReceiveGoodsInfo;
import com.baosight.sczx.zm.cm.domain.ZMCMStockPlanDetail;

/**
 * <p>Title: ServiceZMCMF1.java</p>
 * <p>Description: 到货登记管理-到货明细</p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张小飞
 * @version 1.0
 * <pre>Histroy:
 *          2011-7-5 下午04:52:09  张小飞  Create
 *</pre>
 */
public class ServiceZMCMF1 extends ServiceEPBase {

	/**
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCMF1</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-7-12上午10:51:18 张小飞
	 * </p>
	 *
	*/
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");
		EiInfo outInfo = this.query(inInfo);
		
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.cs.units"));
		outInfo.addBlock(User.getInstance().getConstructionStaff(false));
		
		outInfo.set("validatePeople", UserSession.getUserId());//验收人默认填入当前登录用户
		outInfo.set("depotName", Depot.getDepots().get(0).getFdDepotName());//库房名称默认填入库房管理中建立的一级库房
		outInfo.set("userId", UserSession.getUserId());//用户Id默认填入库确认人
		outInfo.set("userName", UserSession.getInSessionProperty("UserCname"));//用户Name默认填入库确认人
		
		return outInfo;
	}
	
	/**
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCMF1</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-7-12上午10:51:18 张小飞
	 * </p>
	 *
	*/
	@Override
	public EiInfo query(EiInfo inInfo) {
		String fdReceiveId = inInfo.getString("fdReceiveId");
		String fdIsfromPlan = inInfo.getString("fdIsfromPlan");
		StaticTools.setQueryParameters(inInfo, "fdStatus", "正常", true);
		StaticTools.setQueryParameters(inInfo, "fdReceiveId", fdReceiveId, true);
		StaticTools.setQueryParameters(inInfo, "fdIsfromPlan", fdIsfromPlan, true);
		EiInfo outInfo = super.query(inInfo, "ZMCMReceiveGoodsInfo.queryForGridDisplay", new ZMCMReceiveGoodsInfo());
		outInfo.addBlock(generateArrivalType());
		return outInfo;
	}
	
	/**
	 * <p>Function: insert</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCMF1</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-7-12上午10:51:18 张小飞
	 * </p>
	 *
	*/
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public EiInfo insert(EiInfo inInfo) 
	{
		EiInfo outInfo = new EiInfo();
		String fdPlanNum = inInfo.getBlock(EiConstant.resultBlock).getCellStr(0, "fdPlanNum");
		String fdActualNum = inInfo.getBlock(EiConstant.resultBlock).getCellStr(0, "fdActualNum");
		String fdDetailId = "no";
		
		if("1".equals(inInfo.getBlock("result").getCellStr(0, "fdIsfromPlan")))
		{
			fdDetailId = inInfo.getBlock(EiConstant.resultBlock).getCellStr(0, "fdStockPlanDetailId");
		}
		
		if(Double.parseDouble(fdActualNum) - Double.parseDouble(fdPlanNum) > 0)
		{
			inInfo.setStatus(-1);
			inInfo.setMsg("到货数量不得大于应收数量！");
			return inInfo;
		}
		//判断本次的到货物资中，是否有本年度第一次到货物资
		List<String> _list = new ArrayList<String>();
		_list.add(inInfo.getBlock("result").getCellStr(0, "fdMaterialId"));
		Map params = new HashMap();
		params.put("fdMaterialIds", _list);
		params.put("fdYear", StaticTools.getYear());
		
		String rgKey = TablePk.getInstance().getNextValue("T_CM_RECEIVEGOODSINFO");
		inInfo.getBlock("result").setCell(0, "fdKeyId", rgKey);
		inInfo.getBlock("result").setCell(0, "fdValidateStatus", "到货");
		inInfo.getBlock("result").setCell(0, "fdDetailId", fdDetailId);
		outInfo = super.insert(inInfo, "ZMCMReceiveGoodsInfo.insert");
		
		if(outInfo.getStatus() != -1)
		{
			//更新到货主表单据金额
			Map inMap = new HashMap();
			inMap.put("fdKeyId", inInfo.getBlock("result").getCellStr(0, "fdReceiveId"));
			dao.update("ZMCMReceiveGoods.updateSumWithAllDetail", inMap);
		}
		
		if("1".equals(inInfo.getBlock("result").getCellStr(0, "fdIsfromPlan")))
		{
			updateStockPlanInfo(inInfo.getBlock(EiConstant.resultBlock).getCellStr(0, "fdStockPlanDetailId"),
								inInfo.getBlock(EiConstant.resultBlock).getCellStr(0, "fdActualNum"),
								false);
		}
		
		outInfo = this.query(inInfo);
		return outInfo;
	}

	/**
	 * <p>Function: update</p>
	 * <p>Description: 修改</p>
	 * <p>return value: ServiceZMCMF1</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-7-12上午10:51:18 张小飞
	 * </p>
	 *
	*/
	@Override
	public EiInfo update(EiInfo inInfo) 
	{
		String fdPlanNum = inInfo.getBlock(EiConstant.resultBlock).getCellStr(0, "fdPlanNum");
		String fdActualNum = inInfo.getBlock(EiConstant.resultBlock).getCellStr(0, "fdActualNum");
		
		if(Double.parseDouble(fdActualNum) - Double.parseDouble(fdPlanNum) > 0)
		{
			inInfo.setStatus(-1);
			inInfo.setMsg("到货数量不得大于应收数量！");
			return inInfo;
		}
		
		EiInfo outInfo = super.update(inInfo, "ZMCMReceiveGoodsInfo.updateDetails");
		
		if(outInfo.getStatus() != -1)
		{
			//更新到货主表单据金额
			Map inMap = new HashMap();
			inMap.put("fdKeyId", inInfo.getBlock("result").getCellStr(0, "fdReceiveId"));
			dao.update("ZMCMReceiveGoods.updateSumWithAllDetail", inMap);
		}
		
		return outInfo;
	}
	
	/**
	 * 
	 * <p>Function: delete</p>
	 * <p>Description: 删除</p>
	 * <p>return value: EiInfo</p>
	 * <p>History:
	 *    2012-3-6下午02:37:21 wangkun
	 * </p>
	 *
	 */
	public EiInfo delete(EiInfo inInfo) {
		EiInfo _temp = validateDelete(inInfo);
		if(_temp.getStatus() == -1)
		{
			return _temp;
		}
		_temp = super.delete(inInfo, "ZMCMReceiveGoodsInfo.delete");
		
		if(_temp.getStatus() != -1)
		{
			//更新到货主表单据金额
			Map inMap = new HashMap();
			inMap.put("fdKeyId", inInfo.getBlock("result").getCellStr(0, "fdReceiveId"));
			dao.update("ZMCMReceiveGoods.updateSumWithAllDetail", inMap);
		}
		
		if("1".equals(inInfo.get("fdIsfromPlan")))
		{	
			for(int i=0; i<inInfo.getBlock(EiConstant.resultBlock).getRowCount(); i++)
			{
				updateStockPlanInfo(inInfo.getBlock(EiConstant.resultBlock).getCellStr(i, "fdDetailId"),
								inInfo.getBlock(EiConstant.resultBlock).getCellStr(i, "fdActualNum"), 
								true);
			}
		}
		EiInfo outInfo = this.query(inInfo);		
		outInfo.setMsg(_temp.getMsg());
		outInfo.setDetailMsg(_temp.getDetailMsg());
		return outInfo;
	}
	
	private void updateStockPlanInfo(String fdKeyId, String ActualNum, boolean deleteFlag)
	{
			Map map = new HashMap();
			map.put("fdKeyId", fdKeyId);
			List<ZMCMStockPlanDetail> detail = dao.query("ZMCMStockPlanDetail.query", map);
			
			String fdStockPlanId = detail.get(0).getFdStockPlanId();
			//double fdSum = detail.get(0).getFdSum();
			double fdRecevieSum = detail.get(0).getFdRecevieSum();
			double fdActualNum = Double.parseDouble(ActualNum);
			
			//更新采购计划明细信息
			map = new HashMap();
			if(deleteFlag)
			{
				map.put("fdRecevieSum", fdRecevieSum-fdActualNum);
			}
			else
			{
				map.put("fdRecevieSum", fdRecevieSum+fdActualNum);
			}
			
			map.put("fdKeyId", fdKeyId);
			dao.update("ZMCMStockPlanDetail.updateAfterAcceptance", map);
			
			map = new HashMap();
			map.put("fdStockPlanId", fdStockPlanId);
			List<ZMCMStockPlanDetail> detail1 = dao.query("ZMCMStockPlanDetail.query", map);
			
			map = new HashMap();
			map.put("fdPlanStatus", "全部到货");
			for(int j=0; j<detail1.size(); j++)
			{
				double sum = detail1.get(j).getFdSum();
				double recevieSum = detail1.get(j).getFdRecevieSum();
				
				//更新采购计划主表信息
				if(recevieSum != sum)
				{
					map.put("fdPlanStatus", "部分到货");
					break;	
				}
			}
			map.put("fdKeyId", fdStockPlanId);
			dao.update("ZMCMStockPlan.updateAfterAcceptance", map);
	}
	
	/**
	 * 
	 * <p>Function: acceptance</p>
	 * <p>Description: 验收</p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-7-18上午10:52:09 张小飞
	 * </p>
	 *
	 */
	@SuppressWarnings("unchecked")
	public EiInfo acceptance(EiInfo inInfo) {
		String fdKeyId = inInfo.getBlock("result").getCellStr(0, "fdKeyId");//从表主键
		String fdDetailId = inInfo.getBlock("result").getCellStr(0, "fdDetailId");//主表主键
		String fdValidateStatus = "验收";//验收状态
		
		//更新到货明细记录表信息
		inInfo.getBlock("result").setCell(0, "fdKeyId", fdKeyId);
		inInfo.getBlock("result").setCell(0, "fdValidateStatus", fdValidateStatus);
		inInfo.getBlock("result").setCell(0, "fdValidator", UserSession.getUserId());
		EiInfo outInfo = super.update(inInfo, "ZMCMReceiveGoodsInfo.updateForAcceptance");
		
		if(!"no".equals(fdDetailId.trim()))
		{
			Map<String, String> map = new HashMap<String, String>();
			map.put("fdKeyId", fdDetailId);
			List<ZMCMStockPlanDetail> result = dao.query("ZMCMStockPlanDetail.query", map);
			String fdStockPlanId = result.get(0).getFdStockPlanId();
			//double fdSum = result.get(0).getFdSum();
			double fdRecevieSum = result.get(0).getFdRecevieSum(); //== null? 0 : result.get(0).getFdRecevieSum();
			double fdActualNum = Double.parseDouble(inInfo.getBlock("result").getCellStr(0, "fdActualNum"));
			double fdValidateNum = Double.parseDouble(inInfo.getBlock("result").getCellStr(0, "fdValidateNum"));
			
			//更新采购计划明细信息
			inInfo.getBlock("result").setCell(0, "fdRecevieSum", fdRecevieSum+(fdValidateNum-fdActualNum));
			inInfo.getBlock("result").setCell(0, "fdKeyId", fdDetailId);
			super.update(inInfo, "ZMCMStockPlanDetail.updateAfterAcceptance");
			
			
			map = new HashMap<String, String>();
			map.put("fdStockPlanId", fdStockPlanId);
			result = dao.query("ZMCMStockPlanDetail.query", map);
			inInfo.getBlock("result").setCell(0, "fdPlanStatus", "全部到货");
			for(int i=0; i<result.size(); i++)
			{
				double sum = result.get(i).getFdSum();
				double recevieSum = result.get(i).getFdRecevieSum();
				
				//更新采购计划主表信息
				if(recevieSum != sum)
				{
					inInfo.getBlock("result").setCell(0, "fdPlanStatus", "部分到货");
					break;	
				}
			}
			inInfo.getBlock("result").setCell(0, "fdKeyId", fdStockPlanId);
			super.update(inInfo, "ZMCMStockPlan.updateAfterAcceptance");
		}
		return outInfo;
	}
	
	/**
	 * 
	 * <p>Function: validateImport</p>
	 * <p>Description: 验证勾选记录是否有入库权限</p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-11-3 上午09:30:43  wangkun
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public EiInfo validateImport(EiInfo inInfo) 
	{
		List link = new ArrayList();
		EiInfo outInfo = new EiInfo();
		if(inInfo.getBlock("queryResult") != null)
		{
			outInfo.addBlock(inInfo.getBlock("queryResult"));
		}
		String fdMaterialCode = inInfo.get("fdMaterialCode").toString();		
		
		Map inMap = new HashMap();
		String sqlmap = "ZMCMTypeManageMentSet.queryManageAllType";
		String isUseTypeManagement = SystemSettingCM.getInstance().getIsuseTypemanagement();
		if(isUseTypeManagement.equals("1"))
		{
			inMap.put("fdImportPeopleId", UserSession.getUserId());
			List _list = dao.query(sqlmap, inMap);
			link = Utils.generateValidateData(_list);
		}
		else
		{
			sqlmap = "ZMCMMaterialType.type";
			List _list = dao.query(sqlmap, inMap);
    		
			for(int i = 0; i<_list.size(); i++)
			{
				Map _map = (Map)_list.get(i);
				link.add(_map.get("fdTypeCode").toString());
			}
		}

		outInfo.set("fdNoteCode", queryNoteCode());
		
		for(int k=0; k<link.size(); k++)
		{
			if(fdMaterialCode.startsWith(link.get(k).toString()))
			{
				outInfo.setStatus(1);
				return outInfo;
			}
		}
		
		outInfo.setStatus(-1);
		outInfo.setMsg("没有选中物资的入库权限，请重新选择！");
		
		return outInfo;
	}
	
	/**
	 * 
	 * <p>Function: validateCheck</p>
	 * <p>Description: 验证勾选记录是否有验收权限</p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-11-3 上午09:30:43  wangkun
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public EiInfo validateCheck(EiInfo inInfo) 
	{
		List link = new ArrayList();
		EiInfo outInfo = new EiInfo();
		String fdMaterialCode = inInfo.get("fdMaterialCode").toString();
		
		Map inMap = new HashMap();
		String sqlmap = "ZMCMTypeManageMentSet.queryManageAllType";
		String isUseTypeManagement = SystemSettingCM.getInstance().getIsuseTypemanagement();
		if(isUseTypeManagement.equals("1"))
		{
			inMap.put("fdValidatePeopleId", UserSession.getUserId());
			List _list = dao.query(sqlmap, inMap);
			link = Utils.generateValidateData(_list);
		}
		else
		{
			sqlmap = "ZMCMMaterialType.type";
			List _list = dao.query(sqlmap, inMap);
    		
			for(int i = 0; i<_list.size(); i++)
			{
				Map _map = (Map)_list.get(i);
				link.add(_map.get("fdTypeCode").toString());
			}
		}
		
		for(int k=0; k<link.size(); k++)
		{
			if(fdMaterialCode.startsWith(link.get(k).toString()))
			{
				outInfo.setStatus(1);
				return outInfo;
			}
		}
		
		outInfo.setStatus(-1);
		outInfo.setMsg("没有选中物资的验收权限，请重新选择！");
		return outInfo;
	}
	
	/**
	 * 
	 * <p>Function: validateUpdate</p>
	 * <p>Description: 验证勾选记录是否有到货权限</p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-11-3 上午09:30:43  wangkun
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public EiInfo validateUpdate(EiInfo inInfo) 
	{
		List link = new ArrayList();
		EiInfo outInfo = new EiInfo();
		String fdMaterialCode = inInfo.get("fdMaterialCode").toString();
		Map inMap = new HashMap();
		String sqlmap = "ZMCMTypeManageMentSet.queryManageAllType";
		String isUseTypeManagement = SystemSettingCM.getInstance().getIsuseTypemanagement();
		if(isUseTypeManagement.equals("1"))
		{
			inMap.put("fdCheckinPeopleId", UserSession.getUserId());
			List _list = dao.query(sqlmap, inMap);
			link = Utils.generateValidateData(_list);
		}
		else
		{
			sqlmap = "ZMCMMaterialType.type";
			List _list = dao.query(sqlmap, inMap);
    		
			for(int i = 0; i<_list.size(); i++)
			{
				Map _map = (Map)_list.get(i);
				link.add(_map.get("fdTypeCode").toString());
			}
		}
		
		for(int k=0; k<link.size(); k++)
		{
			if(fdMaterialCode.startsWith(link.get(k).toString()))
			{
				outInfo.setStatus(1);
				return outInfo;
			}
		}
		
		outInfo.setStatus(-1);
		outInfo.setMsg("没有选中物资的到货权限，请重新选择！");
		return outInfo;
	}
	
	public EiInfo validateDelete(EiInfo inInfo) 
	{
		List link = new ArrayList();
		EiInfo outInfo = new EiInfo();
		for(int j=0; j<inInfo.getBlock(EiConstant.resultBlock).getRowCount(); j++)
		{
			String fdMaterialCode = inInfo.getBlock(EiConstant.resultBlock).getCellStr(j, "fdMaterialCode");
			
			if(null == fdMaterialCode)
			{
				continue;
			}
			
			Map inMap = new HashMap();
			String sqlmap = "ZMCMTypeManageMentSet.queryManageAllType";
			String isUseTypeManagement = SystemSettingCM.getInstance().getIsuseTypemanagement();
			if(isUseTypeManagement.equals("1"))
			{
				inMap.put("fdCheckinPeopleId", UserSession.getUserId());
				List _list = dao.query(sqlmap, inMap);
				link = Utils.generateValidateData(_list);
			}
			else
			{
				sqlmap = "ZMCMMaterialType.type";
				List _list = dao.query(sqlmap, inMap);
	    		
				for(int i = 0; i<_list.size(); i++)
				{
					Map _map = (Map)_list.get(i);
					link.add(_map.get("fdTypeCode").toString());
				}
			}
			
			boolean hasFlag = false;
			for(int k=0; k<link.size(); k++)
			{
				if(fdMaterialCode.startsWith(link.get(k).toString()))
				{
					hasFlag = true;
				}
			}
			
			if(link.size() == 0 || !hasFlag)
			{
				outInfo.setStatus(-1);
				outInfo.setMsg("没有选中物资的到货权限，请重新选择！");
				return outInfo;
			}
		}
		
		return outInfo;
	}
	
	/**
	 * 
	 * <p>Function: materialcode</p>
	 * <p>Description: 明细customview 取物资信息</p>
	 * <p>return value:EiInfo</p>
	 * <p>History:
	 *    2011-11-3 上午09:30:43  wangkun
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public EiInfo materialcode(EiInfo inInfo) 
	{
		EiInfo outInfo = new EiInfo();
		String fdIsfromPlan = null;
		String fdImport = null;
		if(inInfo.getBlock(EiConstant.queryBlock) != null)
		{
			fdIsfromPlan = inInfo.getBlock(EiConstant.queryBlock).getCellStr(0, "fdIsfromPlan");
			fdImport = inInfo.getBlock(EiConstant.queryBlock).getCellStr(0, "fdImport");
		}
		if(fdIsfromPlan==null || "".equals(fdIsfromPlan))
		{
			fdIsfromPlan="0";
		}
		
		if(fdImport==null || "".equals(fdImport))
		{
			fdImport = "0";
		}
		
		if(fdIsfromPlan.equals("0"))
		{
			outInfo = queryAllMaterial(inInfo, fdImport);
		}
		else
		{
			outInfo = queryStockMaterial(inInfo, fdImport);
		}

		return outInfo;
	}

	private EiInfo queryAllMaterial(EiInfo inInfo, String fdImport) 
	{		
		String typeCode = "(a.fd_material_code like ''";
		Map inMap = new HashMap();
		String sqlmap = "ZMCMTypeManageMentSet.queryManageAllType";
		String isUseTypeManagement = SystemSettingCM.getInstance().getIsuseTypemanagement();
		if(isUseTypeManagement.equals("1"))
		{
			if(fdImport.equals("0"))
			{
				inMap.put("fdCheckinPeopleId", UserSession.getUserId());
			}
			else
			{
				inMap.put("fdImportPeopleId", UserSession.getUserId());
			}
			List _list = dao.query(sqlmap, inMap);
			List queryList = Utils.generateValidateData(_list);
			for(int j=0; j<queryList.size(); j++)
			{
				typeCode += " OR a.fd_material_code like '" + queryList.get(j).toString() + "%'";
			}
			typeCode += ")";
		}
		else
		{
			sqlmap = "ZMCMMaterialType.type";
			List queryList = dao.query(sqlmap, inMap);

			for(int i=0; i<queryList.size(); i++)
			{
				Map _map = (Map)queryList.get(i);
				typeCode += " OR a.fd_material_code like '" + _map.get("fdTypeCode").toString() + "%'";
			}
			typeCode += ")";
		}
		
		if(inInfo.getBlock(EiConstant.queryBlock) == null)
		{
			inInfo.addBlock(EiConstant.queryBlock);
		}
		inInfo.getBlock(EiConstant.queryBlock).setCell(0, "fdMaterialCodeStr", typeCode);
		EiInfo outInfo = super.query(inInfo, "ZMCMMaterialBasicInfo.queryForMaterialcode", new ZMCMMaterialBasicInfo());
		return outInfo;
	}
	
	private EiInfo queryStockMaterial(EiInfo inInfo, String fdImport)
	{
		Map inMap = new HashMap();
		StaticTools.setQueryParameters(inInfo, "fdPlanStatus", "全部到货", true);
		StaticTools.setQueryParameters(inInfo, "fdStatus", "0", true);
		StaticTools.setQueryParameters(inInfo, "isAll", "no", true);
		String typeCode = "(t1.FD_MATERIAL_CODE is null";

		String sqlmap = "ZMCMTypeManageMentSet.queryManageAllType";
		String isUseTypeManagement = SystemSettingCM.getInstance().getIsuseTypemanagement();
		if(isUseTypeManagement.equals("1"))
		{
			if(fdImport.equals("0"))
			{
				inMap.put("fdCheckinPeopleId", UserSession.getUserId());
			}
			else
			{
				inMap.put("fdImportPeopleId", UserSession.getUserId());
			}
			List _list = dao.query(sqlmap, inMap);
			List queryList = Utils.generateValidateData(_list);
			
			for(int j=0; j<queryList.size(); j++)
			{
				typeCode += " OR t1.FD_MATERIAL_CODE like '" + queryList.get(j).toString() + "%'";
			}
			typeCode += ")";
		}
		else
		{
			sqlmap = "ZMCMMaterialType.type";
			List queryList = dao.query(sqlmap, inMap);
			
			for(int i=0; i<queryList.size(); i++)
			{
				Map _map = (Map)queryList.get(i);
				typeCode += " OR t1.FD_MATERIAL_CODE like '" + _map.get("fdTypeCode").toString() + "%'";
			}
			typeCode += ")";
		}
		
		StaticTools.setQueryParameters(inInfo, "fdMaterialCodeStr", typeCode, true);
		EiInfo outInfo = super.query(inInfo, "ZMCMStockPlanDetail.queryInArrivalRegister", new ZMCMStockPlanDetail());
		
		return outInfo;
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	private EiBlock generateArrivalType()
	{
		EiBlock block = new EiBlock("cmes.cm.queryArrivalType");
		EiColumn column = new EiColumn("value");
		column.setDescName("值");
		block.getBlockMeta().addMeta(column);
		
		column = new EiColumn("display");
		column.setDescName("名称");
		block.getBlockMeta().addMeta(column);
		
		Map inMap = new HashMap();
		inMap.put("value", "");
		inMap.put("display", "");
		block.addRow(inMap);
		
		inMap = new HashMap();
		inMap.put("value", "到货");
		inMap.put("display", "到货");
		block.addRow(inMap);
		
		inMap = new HashMap();
		inMap.put("value", "验收");
		inMap.put("display", "验收");
		block.addRow(inMap);
		
		return block;
	}
	
	/**
	 * 
	 * <p>Function: queryNoteCode</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-3-14上午10:48:09 wangkun
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public String queryNoteCode()
	{
		List<Map> _list = new ArrayList<Map>();
		HashMap	params = new HashMap<String, String>();
		String startStr = "RK" + StaticTools.getDateDefault() + StaticTools.getTime().replaceAll(":", "");
		String defaultStr = startStr + "001";//定义格式
		_list = dao.query("ZMCMImportMaterial.querySerialNum", params);
		if(_list!=null && _list.size() > 0) {
			String str = _list.get(0).get("fdNoteCode").toString();
			defaultStr = convertStr(startStr, str);
		}
		
		return defaultStr;
	}
	
	/**
	 * 
	 * <p>Function: convertStr</p>
	 * <p>Description: </p>
	 * <p>return value:String</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-3-14上午10:48:03 wangkun
	 * </p>
	 *
	 */
	private String convertStr(String startStr, String str)
	{
		String str1 = str.substring(16,19);//第二部分的流水号
		int nub = Integer.parseInt(str1); 
		str1 = Integer.toString(nub+1);
		if(str1.length() == 1){
			return startStr+"00"+str1;
		}else if (str1.length() == 2)
		{
			return startStr+"0"+str1;
		}else
		{
			return startStr+str1;
		}
	}
		
}
